{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>name</th>\n",
       "      <th>gender</th>\n",
       "      <th>communcation_skill_score</th>\n",
       "      <th>quantitative_skill_score</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>John</td>\n",
       "      <td>M</td>\n",
       "      <td>40</td>\n",
       "      <td>38</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Alia</td>\n",
       "      <td>F</td>\n",
       "      <td>45</td>\n",
       "      <td>41</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Ananya</td>\n",
       "      <td>F</td>\n",
       "      <td>23</td>\n",
       "      <td>42</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Steve</td>\n",
       "      <td>M</td>\n",
       "      <td>39</td>\n",
       "      <td>48</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Ben</td>\n",
       "      <td>M</td>\n",
       "      <td>39</td>\n",
       "      <td>32</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     name gender  communcation_skill_score  quantitative_skill_score\n",
       "0    John      M                        40                        38\n",
       "1    Alia      F                        45                        41\n",
       "2  Ananya      F                        23                        42\n",
       "3   Steve      M                        39                        48\n",
       "4     Ben      M                        39                        32"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Import pandas library\n",
    "import pandas as pd\n",
    "\n",
    "# Create dataframe\n",
    "sample_data = {'name': ['John', 'Alia', 'Ananya', 'Steve', 'Ben'], \n",
    "               'gender': ['M', 'F', 'F', 'M', 'M'], \n",
    "               'communcation_skill_score': [40, 45, 23, 39, 39],\n",
    "               'quantitative_skill_score': [38, 41, 42, 48, 32]}\n",
    "\n",
    "data = pd.DataFrame(sample_data, columns = ['name', 'gender', 'communcation_skill_score', 'quantitative_skill_score'])\n",
    "data.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "37.2"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# find mean of communication_skill_score column \n",
    "data['communcation_skill_score'].mean(axis=0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "39"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# find mode of communication_skill_score column\n",
    "data['communcation_skill_score'].mode()[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "39.0"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# find median of communication_skill_score column\n",
    "data['communcation_skill_score'].median()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "22\n"
     ]
    }
   ],
   "source": [
    "column_range=data['communcation_skill_score'].max()-data['communcation_skill_score'].min()\n",
    "print(column_range)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1.0\n"
     ]
    }
   ],
   "source": [
    "# First Quartile\n",
    "q1 = data['communcation_skill_score'].quantile(.25)\n",
    "\n",
    "# Third Quartile\n",
    "q3 = data['communcation_skill_score'].quantile(.75)\n",
    "\n",
    "# Inter Quartile Ratio\n",
    "iqr=q3-q1\n",
    "print(iqr)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "69.2"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Variance of communication_skill_score\n",
    "data['communcation_skill_score'].var()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "8.318653737234168"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Standard deviation of communication_skill_score\n",
    "data['communcation_skill_score'].std()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "       communcation_skill_score  quantitative_skill_score\n",
      "count                  5.000000                  5.000000\n",
      "mean                  37.200000                 40.200000\n",
      "std                    8.318654                  5.848077\n",
      "min                   23.000000                 32.000000\n",
      "25%                   39.000000                 38.000000\n",
      "50%                   39.000000                 41.000000\n",
      "75%                   40.000000                 42.000000\n",
      "max                   45.000000                 48.000000\n"
     ]
    }
   ],
   "source": [
    "# Describe dataframe\n",
    "print(data.describe())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 127,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "-1.704679180800373"
      ]
     },
     "execution_count": 127,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# skewness of communication_skill_score column\n",
    "data['communcation_skill_score'].skew()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 128,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3.6010641852384015"
      ]
     },
     "execution_count": 128,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# kurtosis of communication_skill_score column \n",
    "data['communcation_skill_score'].kurtosis()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>communcation_skill_score</th>\n",
       "      <th>quantitative_skill_score</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>communcation_skill_score</th>\n",
       "      <td>69.20</td>\n",
       "      <td>-6.55</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>quantitative_skill_score</th>\n",
       "      <td>-6.55</td>\n",
       "      <td>34.20</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                          communcation_skill_score  quantitative_skill_score\n",
       "communcation_skill_score                     69.20                     -6.55\n",
       "quantitative_skill_score                     -6.55                     34.20"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Covariance between columns of dataframe\n",
    "data.cov()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>communcation_skill_score</th>\n",
       "      <th>quantitative_skill_score</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>communcation_skill_score</th>\n",
       "      <td>1.00000</td>\n",
       "      <td>-0.13464</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>quantitative_skill_score</th>\n",
       "      <td>-0.13464</td>\n",
       "      <td>1.00000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                          communcation_skill_score  quantitative_skill_score\n",
       "communcation_skill_score                   1.00000                  -0.13464\n",
       "quantitative_skill_score                  -0.13464                   1.00000"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Correlation between columns of dataframe\n",
    "data.corr(method ='pearson')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Parametric Test"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## One-Sample t-test"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Mean: 70.5\n",
      "P Value: 0.5986851106160134\n",
      "t-test Value: 0.5454725779039431\n",
      "Hypothesis Accepted\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "\n",
    "from scipy.stats import ttest_1samp\n",
    "\n",
    "data=np.array([63, 75, 84, 58, 52, 96, 63, 55, 76, 83])\n",
    "\n",
    "mean_value = np.mean(data)\n",
    "\n",
    "print(\"Mean:\",mean_value)\n",
    "\n",
    "t_test_value, p_value = ttest_1samp(data, 68)\n",
    "\n",
    "print(\"P Value:\",p_value)\n",
    "\n",
    "print(\"t-test Value:\",t_test_value)\n",
    "\n",
    "# 0.05 or 5% is significance level or alpha.\n",
    "\n",
    "if p_value < 0.05:    \n",
    "\n",
    "    print(\"Hypothesis Rejected\")\n",
    "\n",
    "else:\n",
    "    \n",
    "    print(\"Hypothesis Accepted\")\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 2-sample t-test"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "p-values: 0.015170931362451255\n",
      "t-test: 2.6835879913819185\n",
      "Hypothesis Rejected\n"
     ]
    }
   ],
   "source": [
    "from scipy.stats import ttest_ind\n",
    "\n",
    "data1=np.array([63, 75, 84, 58, 52, 96, 63, 55, 76, 83])\n",
    "\n",
    "data2=np.array([53, 43, 31, 113, 33, 57, 27, 23, 24, 43])\n",
    "\n",
    "# Compare samples\n",
    "\n",
    "stat, p = ttest_ind(data1, data2)\n",
    "\n",
    "print(\"p-values:\",p)\n",
    "\n",
    "print(\"t-test:\",stat)\n",
    "\n",
    "# 0.05 or 5% is significance level or alpha.\n",
    "\n",
    "if p  < 0.05:    \n",
    "\n",
    "    print(\"Hypothesis Rejected\")\n",
    "\n",
    "else:\n",
    "\n",
    "    print(\"Hypothesis Accepted\")    "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Paired t-test"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "p-values: 0.013685575312467715\n",
      "t-test: 3.0548295044306903\n",
      "Hypothesis Rejected\n"
     ]
    }
   ],
   "source": [
    "# paired test\n",
    "from scipy.stats import ttest_rel\n",
    "\n",
    "# Weights before treatment\n",
    "data1=np.array([63, 75, 84, 58, 52, 96, 63, 65, 76, 83])\n",
    "\n",
    "# Weights after treatment\n",
    "data2=np.array([53, 43, 67, 59, 48, 57, 65, 58, 64, 72])\n",
    "\n",
    "# Compare weights\n",
    "\n",
    "stat, p = ttest_rel(data1, data2)\n",
    "\n",
    "print(\"p-values:\",p)\n",
    "\n",
    "print(\"t-test:\",stat)\n",
    "\n",
    "# 0.05 or 5% is the significance level or alpha.\n",
    "\n",
    "if p  < 0.05:    \n",
    "    \n",
    "    print(\"Hypothesis Rejected\")\n",
    "\n",
    "else:\n",
    "\n",
    "    print(\"Hypothesis Accepted\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## One-Way ANOVA"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "p-values: 0.27667556390705783\n",
      "t-test: 1.3480446381965452\n",
      "Hypothesis Accepted\n"
     ]
    }
   ],
   "source": [
    "from scipy.stats import f_oneway\n",
    "\n",
    "# Performance scores of Mumbai location\n",
    "mumbai=[0.14730927, 0.59168541, 0.85677052, 0.27315387, 0.78591207,0.52426114, 0.05007655, 0.64405363, 0.9825853 , 0.62667439]\n",
    "\n",
    "# Performance scores of Chicago location\n",
    "chicago=[0.99140754, 0.76960782, 0.51370154, 0.85041028, 0.19485391,0.25269917, 0.19925735, 0.80048387, 0.98381235, 0.5864963 ]\n",
    "\n",
    "# Performance scores of London location\n",
    "london=[0.40382226, 0.51613408, 0.39374473, 0.0689976 , 0.28035865,0.56326686, 0.66735357, 0.06786065, 0.21013306, 0.86503358]\n",
    "\n",
    "# Compare results using Oneway ANOVA\n",
    "stat, p = f_oneway(mumbai, chicago, london)\n",
    "\n",
    "print(\"p-values:\", p)\n",
    "\n",
    "print(\"t-test:\", stat)\n",
    "\n",
    "\n",
    "if p  < 0.05:    \n",
    "    \n",
    "    print(\"Hypothesis Rejected\")\n",
    "\n",
    "else:\n",
    "\n",
    "    print(\"Hypothesis Accepted\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 105,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([117,  92,  42,  79,  58, 117,  46, 114,  86,  26])"
      ]
     },
     "execution_count": 105,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# import numpy as np\n",
    "# np.random.randint(1,120,size=10)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Non-Parametric Test"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "p-values: 0.059155602774381234\n",
      "Hypothesis Accepted\n"
     ]
    }
   ],
   "source": [
    "from scipy.stats import chi2_contingency\n",
    "\n",
    "# Average performing employees\n",
    "average=[20, 16, 13, 7]\n",
    "\n",
    "# Outstanding performing employees\n",
    "outstanding=[31, 40, 60, 13]\n",
    "\n",
    "# contingency table\n",
    "contingency_table= [average, outstanding]\n",
    "\n",
    "# Apply Test\n",
    "stat, p, dof, expected = chi2_contingency(contingency_table)\n",
    "\n",
    "print(\"p-values:\",p)\n",
    "\n",
    "if p < 0.05:\n",
    "   print(\"Hypothesis Rejected\")\n",
    "\n",
    "else:\n",
    "   print(\"Hypothesis Accepted\")\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Mann-Whitney U-test "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "p-values: 0.007666581056801412\n",
      "Hypothesis Rejected\n"
     ]
    }
   ],
   "source": [
    "from scipy.stats import mannwhitneyu\n",
    "\n",
    "# Sample1\n",
    "\n",
    "data1=[7,8,4,9,8]\n",
    "\n",
    "# Sample2\n",
    "\n",
    "data2=[3,4,2,1,1]\n",
    "\n",
    "# Apply Test\n",
    "\n",
    "stat, p = mannwhitneyu(data1, data2)\n",
    "\n",
    "print(\"p-values:\",p)\n",
    "\n",
    "# 0.01 or 1% is significance level or alpha.\n",
    "\n",
    "if p  < 0.01:    \n",
    "\n",
    "    print(\"Hypothesis Rejected\")\n",
    "\n",
    "else:\n",
    "    print(\"Hypothesis Accepted\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Wilcoxon rank test"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "p-values: 0.025347318677468252\n",
      "Hypothesis Accepted\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/home/avinash/anaconda3/lib/python3.7/site-packages/scipy/stats/morestats.py:2778: UserWarning: Warning: sample size too small for normal approximation.\n",
      "  warnings.warn(\"Warning: sample size too small for normal approximation.\")\n"
     ]
    }
   ],
   "source": [
    "from scipy.stats import wilcoxon\n",
    "\n",
    "# Sample-1\n",
    "data1 = [1, 3, 5, 7, 9]\n",
    "\n",
    "# Sample-2 after treatement \n",
    "data2 = [2, 4, 6, 8, 10]\n",
    "\n",
    "# Apply \n",
    "stat, p = wilcoxon(data1, data2)\n",
    "\n",
    "print(\"p-values:\",p)\n",
    "\n",
    "# 0.01 or 1% is significance level or alpha.\n",
    "\n",
    "if p  < 0.01:    \n",
    "\n",
    "    print(\"Hypothesis Rejected\")\n",
    "\n",
    "else:\n",
    "    print(\"Hypothesis Accepted\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Kruskal–Wallis Test"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "p-values: 0.01997922369138151\n",
      "Hypothesis Accepted\n"
     ]
    }
   ],
   "source": [
    "from scipy.stats import kruskal\n",
    "\n",
    "# Data sample-1\n",
    "x = [38, 18, 39, 83, 15, 38, 63,  1, 34, 50]\n",
    "\n",
    "# Data sample-2\n",
    "y = [78, 32, 58, 59, 74, 77, 29, 77, 54, 59]\n",
    "\n",
    "# Data sample-3\n",
    "z = [117,  92,  42,  79,  58, 117,  46, 114,  86,  26]\n",
    "\n",
    "# Apply kruskal-wallis test\n",
    "stat, p = kruskal(x,y,z)\n",
    "\n",
    "print(\"p-values:\",p)\n",
    "\n",
    "# 0.01 or 1% is significance level or alpha.\n",
    "\n",
    "if p  < 0.01:    \n",
    "\n",
    "    print(\"Hypothesis Rejected\")\n",
    "\n",
    "else:\n",
    "    print(\"Hypothesis Accepted\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
